<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Model_Member
 *
 * @author bxsp
 */
class Admin_model extends CI_Model {

    public function __construct() {
        parent::__construct();
        $this->load->library('encrypt');
    }

    /**
     * 更新站点配置
     * @param type $data
     */
    public function setWebSiteConfig($data = array()) {
        $this->db->empty_table('ci_site_config');
        $data['uid'] = $this->session->userdata('uid');
        $ret = $this->db->replace('ci_site_config', $data);
        return $ret;
    }

    /**
     * 获取站点配置
     * @return type
     */
    public function getWebSiteConfig() {
        //TODO 根据UID查询
        $uid = $this->session->userdata('uid');
        $query = $this->db->get_where('ci_site_config', array('uid' => $uid))->result_array();
        return $query[0];
    }

    public function setTagsConfig($tag_name) {
        $data = array(
            'tag_name' => $tag_name,
            'tag_create_time' => time(),
//            'tag_status' => 1,
        );
        $ret = $this->db->insert('ci_tags_config', $data);
        return $ret;
    }

    public function getTagsConfig() {
        $this->db->order_by('tag_id', 'DESC');
        $this->db->where_not_in('tag_status', 0);
        $query = $this->db->get('ci_tags_config');
        return $query->result_array();
    }
    
    public function getGalleryConfig(){
        $this->db->order_by('gallery_id', 'DESC');
        $this->db->where_not_in('photo_status', 0);
        $query = $this->db->get('ci_gallery');
        return $query->result_array();
    }

    public function getCatConfig() {
        $this->db->order_by('cat_id', 'DESC');
        $this->db->where_not_in('cat_status', 0);
        $query = $this->db->get('ci_cat_config');
        return $query->result_array();
    }

    public function setCatConfig($query = array()) {
        $query['cat_create_time'] = time();
        $ret = $this->db->insert('ci_cat_config', $query);
        return $ret;
    }

    public function addPost($query = array()) {
        $query['post_create_time'] = time();
        $ret = $this->db->insert('ci_post', $query);
        return $ret;
    }

	public function updatePost($query = array()){
		$ret = $this->db->update('ci_post',$query,array('post_id'=>$query['post_id']));
		return $ret;
	}
    
}
